package com.hooya.fa.eu.biz.dao.mapper.stk;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hooya.fa.eu.biz.dao.entity.TempPkpy;
import com.hooya.fa.eu.biz.dao.entity.dto.BsDataDTO;
import com.hooya.fa.eu.biz.dao.entity.dto.TempKcjlDailyHyDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description 1
 * @Author : Zongz
 * @Copyright Copyright (c) 豪雅集团
 * @Create 2024/3/18
 * @Version 1.0.0
 */
@Mapper
@DS("fa_eu")
public interface TempPkpyMapper extends BaseMapper<TempPkpy> {

    void insertBatchSomeColumn(List<TempPkpy> list);

	@DS("fa_eu_daily")
	void insertBatchSomeColumnDaily(@Param("list") List<TempPkpy> list);

    /**
     * 根据时间获取盘亏盘盈列表
     *
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @return list
     */
    @Select("SELECT cpbh, place, date, sum(sl) sl FROM temp_pkpy " +
            "WHERE date >= #{startDate} AND date < #{endDate} AND sl > 0 group by cpbh, place, date")
    List<TempPkpy> getPkpyListByDate(@Param("startDate") String startDate, @Param("endDate") String endDate);

	@DS("fa_eu")
	@Select("SELECT cpbh, place, date, sum(sl) sl FROM temp_pkpy " +
			"WHERE date >= #{startDate} AND date < #{endDate} AND sl > 0 group by cpbh, place, date")
    List<TempPkpy> getPkpyListByDateDaily(@Param("startDate") String startDate, @Param("endDate") String endDate);

    /**
     * 根据cpbh sl hthm获取对应hthm的belongs，设置到EU12的货权中
     *
     * @param cpbh
     * @param sl
     * @param hthm
     * @return
     */
    @Select("SELECT belongs FROM temp_pkpy WHERE cpbh = #{cpbh} AND sl = #{sl} AND hthm = #{hthm}")
    String getBelongsByCpbhSl(@Param("cpbh") String cpbh, @Param("sl") int sl, @Param("hthm") String hthm);


	@Select("SELECT sum(sl) as sl, cpbh, place, belongs, date FROM fa_eu.temp_pkpy WHERE date >= #{startDate} AND date < #{endDate} GROUP BY cpbh,place,belongs,date")
	List<TempKcjlDailyHyDTO> getPkpyData(@Param("startDate") String startDate,@Param("endDate") String endDate);

	List<BsDataDTO> getBsData(@Param("startDate") String startDate, @Param("endDate") String endDate);
}
